package com.ymatou.app.seller.testcase;

import java.math.BigDecimal;
import java.util.Map;

import net.sf.json.JSONObject;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.seller.parameter.AddProductV2Bean;
import com.ymatou.app.seller.parameter.BrandBean;
import com.ymatou.app.seller.parameter.CategoryBean;
import com.ymatou.app.seller.service.AddProductV2Call;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.C2CCallService;
import com.ymttest.utils.TestDataManager;
/**
*发布直播商品接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddProductV2{
	private static AddProductV2Bean	addProductBean;
	private static AddProductV2Call addProductCall;
	private static String accessToken;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发布直播商品接口");
		
		//sellerkorea1
		//sellerauto
		Map authLogin=AuthCallService.authLogin("sellerkorea1", "123456");
		accessToken = (String) authLogin.get("AccessToken");		
		
		//accessToken="F6C0D4D2C51F1703C536C3A44FD36C1DDFAF8494E8D596EEA4B2603B3C3067AA656F7AADAB985AFD96780FD844AF3C957B290A185CD78018";
	}

	@Before
	public void caseUp() {
		addProductCall =new AddProductV2Call();
		addProductBean =new AddProductV2Bean();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addProductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddProductV2_001() {
		Logger.start(true,"发布直播商品成功");
		try {
			//买手		
			Map signAuth=AuthCallService.signAuth(accessToken);		
			int userId =(Integer)signAuth.get("userId");				
			//查询当前是否有有效的直播活动			
			int activityId=C2CCallService.getActivityIdBySeller(accessToken);			
			//当前没有正在直播的活动
			if (activityId==-1){
				//创建一个直播活动
				C2CCallService.createActivity(accessToken);		
			}
			activityId=C2CCallService.getActivityIdBySeller(accessToken);
			
			addProductBean.setAccessToken(accessToken);
			addProductBean.setActivityId(activityId);
			addProductBean.setAppName("Seller");
			BrandBean brand=new BrandBean();
			brand.setBrandName("autotest商品");
			brand.setIsRecommend(true);
			//brand.setRelatedId("");			
			addProductBean.setBrand(new JSONObject().fromObject(brand).toString());			
			Logger.debug("brand:"+new JSONObject().fromObject(brand).toString());
			CategoryBean category=new CategoryBean();
			category.setCategoryId("9");
			category.setIsRecommend(true);
			
			//category.setRelatedId("");
			addProductBean.setCategory(new JSONObject().fromObject(category).toString());
			addProductBean.setClientId("6b807685f0c7bfd3632b0aa689a8abe6");
			addProductBean.setClientType(1);
			addProductBean.setClientUserId(20123134);
			addProductBean.setDelType(7);
			addProductBean.setDeviceToken("F6C0D4D2C51F1703C536C3A44FD36C1DDFAF8494E8D596EEA4B2603B3C3067AA656F7AADAB985AFD96780FD844AF3C957B290A185CD78018");
			//addProductBean.setExpireHours("");
			addProductBean.setFreeShipping(true);
			addProductBean.setGuid(TestDataManager.getRandomUUID());
			addProductBean.setIsTop(0);
			addProductBean.setLimitedNumber(10);
			addProductBean.setNewCustomerPrice(new BigDecimal(10));
			addProductBean.setNoticeRisk(false);
			addProductBean.setOnShelfNow(true);
			addProductBean.setUserId(userId);
			addProductBean.setVipPrice(new BigDecimal(8));
			addProductBean.setWifi(0);
			addProductBean.setApp("seller");
			addProductBean.setOs("iPhone5");
			addProductBean.setPrice(new BigDecimal(12));
			addProductBean.setProductDesc("autotest测试商品");
			addProductBean.setProductPics("http://pc2.img.ymatou.com/G01/shangou/M00/09/B1/rBBlD1aWE-yAcs8mAADmBBciABc019-original_o.jpg");
			addProductBean.setStockNum(10);
			addProductBean.setSys("8.4.1");
			addProductBean.setTariffType(0);
			addProductBean.setUserPosition("中国上海市闸北区珠江创意中心1602");
			addProductBean.setVersion("2.3.1");
			
			addProductCall.setData(addProductBean);
			addProductCall.callService();
			
			Logger.comment("addProductCall send:" + addProductCall.getEntityString());
			Logger.comment("addProductCall response:" + addProductCall.getReturnData());
			
			Logger.verifyEquals(200, addProductCall.getStatus(), "验证添加直播商品是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}